﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class UILayer 
{
    Dictionary<string, BaseWidget> Widgets = new Dictionary<string,BaseWidget>();   
    int LayerSpace = 100;
    GameObject Go;
    public UILayer(EC_Row row,int index,Transform uiRoot) 
    {
        Go = new GameObject(row.Value<string>("LayerName"));
        Go.transform.parent = uiRoot;
        Go.layer = uiRoot.gameObject.layer;
        Go.transform.localPosition = new Vector3(0,0,index * LayerSpace);
    }

    public GameObject ShowWidget(string widgetName,EC_Row row) 
    {
        if (Widgets.Count > 0) 
        {
            return null;
        }
        string PrefabPath = row.Value<string>("PrefabPath");
        GameObject WidgetGo  = (GameObject)GameObject.Instantiate(Resources.Load(PrefabPath));
        WidgetGo.transform.parent = Go.transform;
        WidgetGo.transform.localScale = Vector3.one;
        BaseWidget baseWidget = WidgetGo.GetComponent<BaseWidget>();
        Widgets.Add(widgetName,baseWidget);
        return WidgetGo; 
    }

    public void CloseWidget(string widgetName) 
    {
        GameObject.Destroy(Widgets[widgetName].gameObject);
        Widgets.Remove(widgetName);
    }
}
